using UnityEngine;
using UnityEngine.UI;
using Voodoo.Pattern;

namespace __Naptime.Script.Adapter
{
	public class InteractiveButtonUpgradeAdapter : MonoBehaviour
	{
		private enum Upgrade
		{
			Length = 0,
			Fuel = 1,
			Power = 2,
			Size = 3
		}

		[SerializeField]
		private Upgrade upgrade;

		[SerializeReference]
		private Image selector;

		private void Awake()
		{
			Shop.OnChecked += OnChecked;
		}

		private void OnDestroy()
		{
			Shop.OnChecked -= OnChecked;
		}

		private void OnChecked()
		{
			if (!(SingletonMB<Shop>.Instance == null) && !(selector == null))
			{
				bool flag = upgrade switch
				{
					Upgrade.Length => SingletonMB<Shop>.Instance.IsLengthLocked(), 
					Upgrade.Fuel => SingletonMB<Shop>.Instance.IsFuelLocked(), 
					Upgrade.Power => SingletonMB<Shop>.Instance.IsPowerLocked(), 
					Upgrade.Size => SingletonMB<Shop>.Instance.IsSizeLocked(), 
					_ => true, 
				};
				selector.color = (flag ? ActivityUtility.UNACTIVE : ActivityUtility.ACTIVE);
			}
		}
	}
}
